<template>
  <div class="contract_manage_detail">
    <el-dialog width="1200px" :visible.sync="formShow" @close="handleClickDeal('cancel')" v-dialog-drag :modal-append-to-body="false" :close-on-click-modal="false" append-to-body>
      <span slot="title">
        <i class="iconfont icon-hetongguanli"></i>
        <span>{{ actionText }}{{ title }}</span>
      </span>

      <div style="height: 650px; overflow-y: auto;">
        <el-form :model="formBaseData" ref="formBaseData" :rules="formBaseRules">
          <el-row>
            <el-col :span="24">
              <el-form-item label="考核周期" prop="assessmentDuration" :label-width="formlabelWidth">
                <div class="flex-left">
                  <el-date-picker size="small" style="width: 250px;" v-model="formBaseData.year" value-format="yyyy" :disabled="detailType === 'check'" type="year" placeholder="选择年">
                  </el-date-picker>

                  <el-select size="small" style="width:250px;margin-left: 10px;" class="half" v-model="formBaseData.assessmentDuration" filterable :disabled="detailType === 'check'">
                    <el-option v-for="item in assessmentDurationOptions" :key="item.value" :label="item.label" :value="item.value">
                    </el-option>
                  </el-select>
                </div>
              </el-form-item>
            </el-col>
          </el-row>

          <el-row>
            <el-col :span="24" class="flex-left">
              <el-form-item label="项目名称" prop="projectId" :label-width="formlabelWidth">
                <!-- <el-input class="input" size="small" v-model="formBaseData.assessmentTeam" placeholder="请输入项目名称" clearable :disabled="detailType == 'check'"></el-input> -->
                <el-select size="small" style="width:250px;" v-model="formBaseData.projectId" filterable :disabled="detailType === 'check'" placeholder="选择项目名称" clearable @change="changeProject">
                  <el-option v-for="(item,index) in projectTree" :key="item.name+index" :label="item.name" :value="item.id">
                  </el-option>
                </el-select>
              </el-form-item>
              <!-- 标段 -->
              <el-form-item label="标段" prop="sectionId" label-width="60px">
                <el-select size="small" style="width:200px;" v-model="formBaseData.sectionId" filterable :disabled="detailType === 'check'" placeholder="选择标段" clearable>
                  <el-option v-for="item in sectionTree" :key="item.name" :label="item.name" :value="item.id">
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>

          <el-row>
            <el-col :span="24">
              <el-form-item label="总分" prop="number" :label-width="formlabelWidth">
                <el-input class="contract_input" size="small" :value="totalScore" placeholder="" disabled>
                  <div slot="suffix">分</div>
                </el-input>
              </el-form-item>
            </el-col>
          </el-row>

          <el-row>
            <el-col :span="24" style="position: relative" class="otherMeterageUpload">
              <el-form-item label="附件" :label-width="formlabelWidth">
                <cmsUploadFile ref="fileOne" :detail-id="detailId" :fileSystem="fileSystem['one']" :disabled="detailType === 'check'|| detailType === 'approve'" type="mul" :fileList="fileList" info="支持上传 png/jpg/gif/doc/xlsx/ppt/pdf等文件" :detail-type="detailType" />
                <el-button v-if="detailType !== 'build'" class="delete" size="small" style="width: 110px;" @click="exportExcel"><i class="iconfont icon-daochu"></i> 导出评分</el-button>
              </el-form-item>

            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <table class="assessment-score-table" border="1" style="border-collapse: collapse;">
                <colgroup>
                  <col style="width: 80px">
                  <col style="width: 200px">
                  <col style="width: 60px">
                  <col style="width: 120px">
                  <col style="">
                  <col style="width: 100px">
                  <col style="width: 200px">
                </colgroup>
                <tr>
                  <th>考核内容</th>
                  <th>考核标准</th>
                  <th>考评分数</th>
                  <th>评分标准</th>
                  <th>评分细则</th>
                  <th>评分</th>
                  <th>备注</th>
                </tr>
                <tr>
                  <td rowspan="4">工程质量</td>
                  <td rowspan="4">
                    严禁发生重大
                    质量事故，一
                    次交验合格率
                    达到 95%以上；
                    分部、分项验
                    收合格率达到
                    100%，确保省
                    级优质工程
                  </td>
                  <td rowspan="4">
                    20分
                  </td>
                  <td>
                    现场质量保证条件5分
                  </td>
                  <td>
                    质量管理及责任制度未落实扣1分；施工操作标准质量验收规范配置不齐全每项扣1分；未按照施工组织设计，施工方案施工每项扣1分，扣完为止。 </td>
                  <td>
                    <el-form-item label-width="0" prop="xczlbztjScore">
                      <el-input v-model="formBaseData.xczlbztjScore" :disabled="detailType === 'check'"></el-input>
                    </el-form-item>
                  </td>
                  <td>
                    <el-form-item label-width="0">
                      <el-input v-model="formBaseData.xczlbztjNote" :disabled="detailType === 'check'"></el-input>
                    </el-form-item>
                  </td>
                </tr>
                <tr>
                  <td>质量记录5分</td>
                  <td>
                    施工记录不全每项扣1分；发生质量责任事故扣2分；业主单位、监理单位及项目部下发的质量整改指令每份扣1分，扣完为止。
                  </td>
                  <td>
                    <el-form-item label-width="0" prop="zljlScore">
                      <el-input v-model="formBaseData.zljlScore" :disabled="detailType === 'check'"></el-input>
                    </el-form-item>
                  </td>
                  <td>
                    <el-form-item label-width="0">
                      <el-input v-model="formBaseData.zljlNote" :disabled="detailType === 'check'"></el-input>
                    </el-form-item>
                  </td>
                </tr>
                <tr>
                  <td>实测指标5分</td>
                  <td>
                    实测项目不满足规范要求的，每项扣1分，扣完为止。
                  </td>
                  <td>
                    <el-form-item label-width="0" prop="sczbScore">
                      <el-input v-model="formBaseData.sczbScore" :disabled="detailType === 'check'"></el-input>
                    </el-form-item>
                  </td>
                  <td>
                    <el-form-item label-width="0">
                      <el-input v-model="formBaseData.sczbNote" :disabled="detailType === 'check'"></el-input>
                    </el-form-item>
                  </td>
                </tr>
                <tr>
                  <td>观感质量5分</td>
                  <td>
                    外观质量有明显缺陷的，每处扣1分，扣完为止
                  </td>
                  <td>
                    <el-form-item label-width="0" prop="zlggScore">
                      <el-input v-model="formBaseData.zlggScore" :disabled="detailType === 'check'"></el-input>
                    </el-form-item>
                  </td>
                  <td>
                    <el-form-item label-width="0">
                      <el-input v-model="formBaseData.zlggNote" :disabled="detailType === 'check'"></el-input>
                    </el-form-item>
                  </td>
                </tr>
                <tr>
                  <td rowspan="4">安全生产</td>
                  <td rowspan="4">
                    严格落实安全
                    生产主体责任，遵守安全操作规程，强化现场管理，确保工程建设中不发生死亡 事故
                  </td>
                  <td rowspan="4">
                    25分
                  </td>
                  <td>
                    安全责任事故5分
                  </td>
                  <td>
                    发生安全事故直接扣5分。列入班组黑名单。
                  </td>
                  <td>
                    <el-form-item label-width="0" prop="aqzrsgScore">
                      <el-input v-model="formBaseData.aqzrsgScore" :disabled="detailType === 'check'"></el-input>
                    </el-form-item>
                  </td>
                  <td>
                    <el-form-item label-width="0">
                      <el-input v-model="formBaseData.aqzrsgNote" :disabled="detailType === 'check'"></el-input>
                    </el-form-item>
                  </td>
                </tr>
                <tr>
                  <td>安全责任制7分</td>
                  <td>
                    未落实建立安全生产主体责任制扣3分；未落实各工种安全技术操作规程扣3分；未按规定配备专、兼职安全员的缺1名扣1分；特种作业人员未
                    持证上岗的发现1名扣1分，至扣完为止
                  </td>
                  <td>
                    <el-form-item label-width="0" prop="aqzrzScore">
                      <el-input v-model="formBaseData.aqzrzScore" :disabled="detailType === 'check'"></el-input>
                    </el-form-item>
                  </td>
                  <td>
                    <el-form-item label-width="0">
                      <el-input v-model="formBaseData.aqzrzNote" :disabled="detailType === 'check'"></el-input>
                    </el-form-item>
                  </td>
                </tr>
                <tr>
                  <td>安全教育7分</td>
                  <td>
                    未落实安全“三级”教育制度扣3分；无书面安全教育内容扣1分；未对工人进行安全交底扣2分；安全教育未经工人签字扣1分；未参加“安全生产月”活动扣1分,至扣完为止
                  </td>
                  <td>
                    <el-form-item label-width="0" prop="aqjyScore">
                      <el-input v-model="formBaseData.aqjyScore" :disabled="detailType === 'check'"></el-input>
                    </el-form-item>
                  </td>
                  <td>
                    <el-form-item label-width="0">
                      <el-input v-model="formBaseData.aqjyNote" :disabled="detailType === 'check'"></el-input>
                    </el-form-item>
                  </td>
                </tr>
                <tr>
                  <td>安全检查6分</td>
                  <td>
                    无定期安全检查制度扣1分；班组对工作队伍未开展安全检查扣1分；班组未按要求进行自查扣1分； 检查出来的隐患未及时整改扣1分，至扣完为止；业主单位、监理单位及项目部下发的安全整改指令每份扣1分，扣完为止。
                  </td>
                  <td>
                    <el-form-item label-width="0" prop="aqjcScore">
                      <el-input v-model="formBaseData.aqjcScore" :disabled="detailType === 'check'"></el-input>
                    </el-form-item>
                  </td>
                  <td>
                    <el-form-item label-width="0">
                      <el-input v-model="formBaseData.aqjcNote" :disabled="detailType === 'check'"></el-input>
                    </el-form-item>
                  </td>
                </tr>
                <tr>
                  <td rowspan="3">项目进度</td>
                  <td rowspan="3">
                    统筹规划，周
                    密安排，保质
                    保量，按工期
                    计划完成每一
                    阶段任务
                  </td>
                  <td rowspan="3">15分</td>
                  <td>
                    施工进度
                    计划5分
                  </td>
                  <td>
                    未按规定进行进度管理工作扣1分；业主单位、监理单位及项目部下发的进度督促指令每份扣1分，扣完为止。
                  </td>
                  <td>
                    <el-form-item label-width="0" prop="sgjdScore">
                      <el-input v-model="formBaseData.sgjdScore" :disabled="detailType === 'check'"></el-input>
                    </el-form-item>
                  </td>
                  <td>
                    <el-form-item label-width="0">
                      <el-input v-model="formBaseData.sgjdNote" :disabled="detailType === 'check'"></el-input>
                    </el-form-item>
                  </td>
                </tr>
                <tr>
                  <td>施工进度完成情况5分</td>
                  <td>未按规定完成进度工作，每加减一个百分点应加减0.2分，至扣完为止</td>
                  <td>
                    <el-form-item label-width="0" prop="sgjdwcqkScore">
                      <el-input v-model="formBaseData.sgjdwcqkScore" :disabled="detailType === 'check'"></el-input>
                    </el-form-item>
                  </td>
                  <td>
                    <el-form-item label-width="0">
                      <el-input v-model="formBaseData.sgjdwcqkNote" :disabled="detailType === 'check'"></el-input>
                    </el-form-item>
                  </td>
                </tr>
                <tr>
                  <td>施工技术措施方案情况5分</td>
                  <td>未按照施工技术方案施工投入人员机械的，扣2分，
                    未按照正确的施工工序施工的，每处扣1分，扣完
                    为止
                  </td>
                  <td>
                    <el-form-item label-width="0" prop="sgjscsfaScore">
                      <el-input v-model="formBaseData.sgjscsfaScore" :disabled="detailType === 'check'"></el-input>
                    </el-form-item>
                  </td>
                  <td>
                    <el-form-item label-width="0">
                      <el-input v-model="formBaseData.sgjscsfaNote" :disabled="detailType === 'check'"></el-input>
                    </el-form-item>
                  </td>
                </tr>
                <tr>
                  <td rowspan="2">工程效益</td>
                  <td rowspan="2">
                    以“不突破预算”为目标，严格控制成本支出，精打细算，厉行节约，反对浪费，提高效益
                  </td>
                  <td rowspan="2">10分</td>
                  <td>成品合格率控制情况5分</td>
                  <td>出现返工和报废，每出现一次扣3分，直至扣完</td>
                  <td>
                    <el-form-item label-width="0" prop="cbhglkzScore">
                      <el-input v-model="formBaseData.cbhglkzScore" :disabled="detailType === 'check'"></el-input>
                    </el-form-item>
                  </td>
                  <td>
                    <el-form-item label-width="0">
                      <el-input v-model="formBaseData.cbhglkzNote" :disabled="detailType === 'check'"></el-input>
                    </el-form-item>
                  </td>
                </tr>
                <tr>
                  <td>厉行节约监督情况5分</td>
                  <td>每发生一次浪费事件扣2分，至扣完为止</td>
                  <td>
                    <el-form-item label-width="0" prop="lxjyjdqkScore">
                      <el-input v-model="formBaseData.lxjyjdqkScore" :disabled="detailType === 'check'"></el-input>
                    </el-form-item>
                  </td>
                  <td>
                    <el-form-item label-width="0">
                      <el-input v-model="formBaseData.lxjyjdqkNote" :disabled="detailType === 'check'"></el-input>
                    </el-form-item>
                  </td>
                </tr>
                <tr>
                  <td rowspan="3">廉政建设</td>
                  <td rowspan="3">遵纪守法，按章办事，公开透明，不发生违法违纪案件</td>
                  <td rowspan="3">10分</td>
                  <td>建设资金的监督管理3分</td>
                  <td>视建设资金监督落实情况进行加减分</td>
                  <td>
                    <el-form-item label-width="0" prop="jszjjdglScore">
                      <el-input v-model="formBaseData.jszjjdglScore" :disabled="detailType === 'check'"></el-input>
                    </el-form-item>
                  </td>
                  <td>
                    <el-form-item label-width="0">
                      <el-input v-model="formBaseData.jszjjdglNote" :disabled="detailType === 'check'"></el-input>
                    </el-form-item>
                  </td>
                </tr>
                <tr>
                  <td>规范工程建设管理3分</td>
                  <td>管理人员中，每次出现一人次违纪扣1分，出现重大违纪扣3分，出现重大违法扣4分</td>
                  <td>
                    <el-form-item label-width="0" prop="gfgcjsglScore">
                      <el-input v-model="formBaseData.gfgcjsglScore" :disabled="detailType === 'check'"></el-input>
                    </el-form-item>
                  </td>
                  <td>
                    <el-form-item label-width="0">
                      <el-input v-model="formBaseData.gfgcjsglNote" :disabled="detailType === 'check'"></el-input>
                    </el-form-item>
                  </td>
                </tr>
                <tr>
                  <td>不拖欠职工工资，保障职工生产生活条件4分</td>
                  <td>拖欠民工工资扣3分；不按时为职工发放工资扣4分；职工生产生活后勤保障不到位扣3分，扣完为止。</td>
                  <td>
                    <el-form-item label-width="0" prop="bzzgscshtjScore">
                      <el-input v-model="formBaseData.bzzgscshtjScore" :disabled="detailType === 'check'"></el-input>
                    </el-form-item>
                  </td>
                  <td>
                    <el-form-item label-width="0">
                      <el-input v-model="formBaseData.bzzgscshtjNote" :disabled="detailType === 'check'"></el-input>
                    </el-form-item>
                  </td>
                </tr>
                <tr>
                  <td rowspan="2">智能信息</td>
                  <td rowspan="2">通过信息化手段加强现场的 质量、安全、进度、造价等方面的管理；注重信息宣传</td>
                  <td rowspan="2">10分</td>
                  <td>智慧工地系统5分</td>
                  <td>相关板块文件未及时上传智慧工地系统扣3分，未设置智慧工地系统专员扣2分。</td>
                  <td>
                    <el-form-item label-width="0" prop="jhgdxtScore">
                      <el-input v-model="formBaseData.jhgdxtScore" :disabled="detailType === 'check'"></el-input>
                    </el-form-item>
                  </td>
                  <td>
                    <el-form-item label-width="0">
                      <el-input v-model="formBaseData.jhgdxtNote" :disabled="detailType === 'check'"></el-input>
                    </el-form-item>
                  </td>
                </tr>
                <tr>
                  <td>开展宣传工作5分</td>
                  <td>每月未进行相关宣传工作扣3分，不积极进行宣传报道工作扣2分。</td>
                  <td>
                    <el-form-item label-width="0" prop="kzxcgzScore">
                      <el-input v-model="formBaseData.kzxcgzScore" :disabled="detailType === 'check'"></el-input>
                    </el-form-item>
                  </td>
                  <td>
                    <el-form-item label-width="0">
                      <el-input v-model="formBaseData.kzxcgzNote" :disabled="detailType === 'check'"></el-input>
                    </el-form-item>
                  </td>
                </tr>
                <tr>
                  <td rowspan="2">环境保护</td>
                  <td rowspan="2">保护施工现场环境生态，时刻牢记“绿水青山，就是金山银山 ”的理念。加强施工现场环境监管</td>
                  <td rowspan="2">10分</td>
                  <td>施工现场的环境保护5分</td>
                  <td>有泥浆池外泄扣2分，便道清理不及时扬尘控制不到位扣2分，施工现场杂乱扣1分。</td>
                  <td>
                    <el-form-item label-width="0" prop="hjbhScore">
                      <el-input v-model="formBaseData.hjbhScore" :disabled="detailType === 'check'"></el-input>
                    </el-form-item>
                  </td>
                  <td>
                    <el-form-item label-width="0">
                      <el-input v-model="formBaseData.hjbhNote" :disabled="detailType === 'check'"></el-input>
                    </el-form-item>
                  </td>
                </tr>
                <tr>
                  <td>生活区的环境保护5分</td>
                  <td>生活区污水乱排扣2分，垃圾未及时清理扣2分，
                    公共区未及时打扫清理扣1分，食堂公厕未定时清理扣1分，扣完为止。</td>
                  <td>
                    <el-form-item label-width="0" prop="shqdhjbhScore">
                      <el-input v-model="formBaseData.shqdhjbhScore" :disabled="detailType === 'check'"></el-input>
                    </el-form-item>
                  </td>
                  <td>
                    <el-form-item label-width="0">
                      <el-input v-model="formBaseData.shqdhjbhNote" :disabled="detailType === 'check'"></el-input>
                    </el-form-item>
                  </td>
                </tr>
              </table>
            </el-col>
          </el-row>
          <div style="clear:both;"></div>
        </el-form>
      </div>

      <div slot="footer" class="dialog-footer">
        <!--api操作按钮 除去上报-->
        <!--新建和编辑的暂存上报-->
        <template v-if="detailType === 'build' || detailType === 'edit'">
          <el-button size="small" type="primary" :loading="isLoading" @click="handleClickDeal('submit', { flag: 1 })"><i class="iconfont icon-icon_save"></i> 确
            定</el-button>
        </template>
        <el-button size="small" @click="handleClickDeal('cancel')"><i class="iconfont icon-guanbi"></i> 取
          消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { totalScoreFilter, assessmentDurationOptions } from '../assessment-score'
import crudDict from "@/api/system/dict";
export default {
  name: "assessment-score-detail",
  props: {
    postDetail: {
      type: Object,
      default: {
        show: false,
        type: 'build',
        params: {}
      }
    }
  },
  watch: {
    postDetail(value) {
      console.log(value)
      this.projectTree = this.$parent.projectTree
      this.getConstructionTeam();
      // 显示详情弹窗
      this.formShow = value.show
      // 初始化窗口参数
      this.activeName = 'first'
      // 详情类型
      this.detailType = value.type
      // 详情的流程操作处理
      this.detailActions.splice(0, this.detailActions.length)
      if (value.params) {
        for (let key in value.params.actions) {
          if (key !== 'show' && key !== 'update' && key !== 'getHistory') {
            this.$set(this.detailActions, this.detailActions.length, {
              name: value.params.actions[key].name,
              url: value.params.actions[key].url,
              key: key,
            })
          }
        }
      }
      // 详情id
      this.detailId = value === undefined ? 0 : value.detailId
      // 非新建详情时 获取详情
      if (this.detailType === 'history') {
      }
      else if (this.detailType !== 'build') {
        this.getDetail()
      }
      if (this.detailType === 'build') {
      }
    }
  },
  computed: {
    actionText() {
      switch (this.detailType) {
        case 'build':
          return '新增';
        case 'update':
          return '修改'
        case 'check':
          break
      }
      return '查看'
    },
    totalScore() {
      return totalScoreFilter(this.formBaseData)
    }
  },
  data() {
    const limitNumber = (max, min) => (rule, value, callback) => {
      value = Number(value)
      if (value <= max && value >= min) {
        callback()
      } else {
        callback(new Error('请输入正确范围的分值'))
      }
    }
    return {
      isLoading: false,
      detailType: 'build', // 详情类型 build新建 check不可编辑查看 edit编辑
      detailId: '', // 当前详情的id
      detailActions: [], // 当前详情的操作项
      formShow: false, // 表单展示
      formlabelWidth: '130px', // 表单左侧标题宽度
      formlabelRightWidth: '110px', // 表单左侧标题宽度
      formlabelWidth2: '111px', // 表单左侧标题宽度
      title: '考核评分',
      fileSystem: {
        'one': {
          sys: 'buss',
          module: 'assessment',
          part: 'one',
          compoName: 'fileOne'
        }
      },
      constructionTeamList: [],
      formBaseData: {
        assessmentDuration: '',
        assessmentTeam: '',
        year: '',
        value: 1,
        xczlbztjScore: '',
        xczlbztjNote: '',
        zljlScore: '',
        zljlNote: '',
        sczbScore: '',
        sczbNote: '',
        zlggScore: '',
        zlggNote: '',
        aqzrsgScore: '',
        aqzrsgNote: '',
        aqzrzScore: '',
        aqzrzNote: '',
        aqjyScore: '',
        aqjyNote: '',
        aqjcScore: '',
        aqjcNote: '',
        sgjdScore: '',
        sgjdNote: '',
        sgjdwcqkScore: '',
        sgjdwcqkNote: '',
        sgjscsfaScore: '',
        sgjscsfaNote: '',
        cbhglkzScore: '',
        cbhglkzNote: '',
        lxjyjdqkScore: '',
        lxjyjdqkNote: '',
        jszjjdglScore: '',
        jszjjdglNote: '',
        gfgcjsglScore: '',
        gfgcjsglNote: '',
        bzzgscshtjScore: '',
        bzzgscshtjNote: '',
        jhgdxtScore: '',
        jhgdxtNote: '',
        kzxcgzScore: '',
        kzxcgzNote: '',
        hjbhScore: '',
        hjbhNote: '',
        shqdhjbhScore: '',
        shqdhjbhNote: '',
        projectId: '',
        sectionId: ''
      }, // 表单基本信息内容
      assessmentDurationOptions: assessmentDurationOptions,
      assessmentTeamOptions: [
        { label: '考核班组1', value: '考核班组1' },
        { label: '考核班组2', value: '考核班组2' },
      ],
      fileList: [],
      fileListArray: [],
      tableValue: {
        value1: 1
      },
      formBaseRules: {
        // number: [
        //     { required: true, message: '请输入' + '合同编号', trigger: 'blur' },
        // ],
        // title: [
        //     { required: true, message: '请输入' + '合同名称', trigger: 'blur' },
        // ],
        // amount: [
        //     { required: true, message: '请输入' + '合同总金额', trigger: 'blur' },
        // ],
        // type: [
        //     { required: true, message: '请选择' + '合同类型', trigger: 'change' },
        // ]
        projectId: [
          { required: true, message: '请选择' + '项目名称', trigger: 'change' },
        ],
        sectionId: [
          { required: true, message: '请选择' + '项目名称', trigger: 'change' },
        ],
        assessmentTeam: [
          { required: true, message: '请选择' + '考核班组', trigger: 'change' },
        ],
        assessmentDuration: [
          { required: true, message: '请选择' + '考核周期', trigger: 'change' },
        ],
        xczlbztjScore: [
          { require: true, trigger: 'change', validator: limitNumber(5, 0) }
        ],
        zljlScore: [
          { require: true, trigger: 'change', validator: limitNumber(5, 0) }
        ],
        sczbScore: [
          { require: true, trigger: 'change', validator: limitNumber(5, 0) }
        ],
        zlggScore: [
          { require: true, trigger: 'change', validator: limitNumber(5, 0) }
        ],
        aqzrsgScore: [
          { require: true, trigger: 'change', validator: limitNumber(5, 0) }
        ],
        aqzrzScore: [
          { require: true, trigger: 'change', validator: limitNumber(7, 0) }
        ],
        aqjyScore: [
          { require: true, trigger: 'change', validator: limitNumber(7, 0) }
        ],
        aqjcScore: [
          { require: true, trigger: 'change', validator: limitNumber(6, 0) }
        ],
        sgjdScore: [
          { require: true, trigger: 'change', validator: limitNumber(5, 0) }
        ],
        sgjdwcqkScore: [
          { require: true, trigger: 'change', validator: limitNumber(5, 0) }
        ],
        sgjscsfaScore: [
          { require: true, trigger: 'change', validator: limitNumber(5, 0) }
        ],
        cbhglkzScore: [
          { require: true, trigger: 'change', validator: limitNumber(5, 0) }
        ],
        lxjyjdqkScore: [
          { require: true, trigger: 'change', validator: limitNumber(5, 0) }
        ],
        jszjjdglScore: [
          { require: true, trigger: 'change', validator: limitNumber(3, 0) }
        ],
        gfgcjsglScore: [
          { require: true, trigger: 'change', validator: limitNumber(3, 0) }
        ],
        bzzgscshtjScore: [
          { require: true, trigger: 'change', validator: limitNumber(4, 0) }
        ],
        jhgdxtScore: [
          { require: true, trigger: 'change', validator: limitNumber(5, 0) }
        ],
        kzxcgzScore: [
          { require: true, trigger: 'change', validator: limitNumber(5, 0) }
        ],
        hjbhScore: [
          { require: true, trigger: 'change', validator: limitNumber(5, 0) }
        ],
        shqdhjbhScore: [
          { require: true, trigger: 'change', validator: limitNumber(5, 0) }
        ]

        // principalOfSecondParty: [
        //     { required: true, message: '请输入' + '合同负责人(乙方)', trigger: 'blur' },
        // ],
        // associatedBlock: [
        //     { required: true, message: '请选择' + '关联标段', trigger: 'change' },
        // ],

        /*GIS: [
          { required: true, message: '请输入' + 'GIS位置', trigger: 'blur' },
        ],*/
      }, // 表单基本信息验证
      projectTree: [],
      sectionTree: []
    }
  },

  created() {
  },

  methods: {
    // 获取详情请求 api
    getDetail() {
      this.$httpGet(
        `/buss/assessment/getOne?id=${this.detailId}`,
        {}).then(res => {
          if (res.code === 200) {
            let data = res.data
            // 表单信息
            this.formBaseData = data
            if (!this.formBaseData.projectId) {
              this.$set(this.formBaseData, 'projectId', '')
            } else {
              // 标段数据回显问题
              this.sectionTree = []
              for (let i = 0; i < this.projectTree.length; i++) {
                if (this.projectTree[i].id == this.formBaseData.projectId) {
                  this.sectionTree = this.projectTree[i].children
                  break;
                }
              }
            }
            if (!this.formBaseData.sectionId) {
              this.$set(this.formBaseData, 'sectionId', '')
            }
            // 文件系统
            this.loadFiles();
          } else {
            this.$messageError(res.data.message)
          }
        }).catch(res => {
          console.log('请求出现错误', res);
          this.$messageError(this.$route.name + '获取详情请求-请求失败')
        })
    },
    loadFiles() {
      this.$nextTick(() => {
        for (let k in this.fileSystem) {
          let fileProp = this.fileSystem[k]
          this.$refs[fileProp.compoName].init()
        }
      })
    },
    // 提交详情 提交1/暂存0 新建0/修改1
    submitDetail(type, callback) {
      console.log(this.detailType)
      let submit = '/buss/assessment/add'
      if (this.detailType === 'build') {
        submit = '/buss/assessment/add'
      } else {
        submit = '/buss/assessment/edit'
      }
      this.$httpPost(submit, this.formBaseData).then(res => {
        if (res.code === 200) {
          this.$messageSuccess('保存成功')
          this.detailId = !this.detailId ? res.data.id : this.detailId
          // this.$refs.cmsFileTable.bindAllFile(this.detailId)
          this.isLoading = false
          if (callback) callback()
        } else {
          this.isLoading = false
          this.$messageError(res.data.message)
        }
      }).catch(res => {
        console.log('请求出现错误', res);
        this.isLoading = false
        this.$messageError(this.$route.name + '提交详情-请求失败')
      })
    },
    // 事件处理的api请求
    sealDealHttp(url, query, params, callback) {
      this.$httpPost(
        this.$store.state.httpHost.buss + url + query,
        params
      ).then(res => {
        if (res.data.status === 1) {
          if (callback) callback(res.data)
        } else {
          this.$messageError(res.data.message)
        }
      }).catch(res => {
        console.log(res)
      })
    },
    // 点击各个流程的按钮事件
    handleClickDeal(type, res) {
      console.log(type, res)
      switch (type) {
        // 取消，关闭窗口
        case 'cancel':
          // 重置表单验证
          this.$refs['formBaseData'].resetFields()
          // 清空表单内容
          this.formBaseData = {
            assessmentDuration: '',
            assessmentTeam: '',
            projectId: '',
            sectionId: ''
          } // 表单基本信息内容
          this.sectionTree = []
          // 关闭弹窗
          this.formShow = false
          break
        // 保存
        case 'submit':
          let flag = res.flag
          // 表单验证
          this.$refs['formBaseData'].validate((valid) => {
            if (valid) {
              // 再验证其他内容
              // 整理文件信息
              this.isLoading = true
              let files = []
              console.log(this.fileList)
              this.fileList.forEach(item => {
                files.push(item.id)
              })
              // 提交详情
              this.submitDetail(flag, () => {
                // 绑定文件到表单
                // if (this.detailType === 'build') {
                //     this.bingFileForm(files, this.fileSystem.part[0], () => { })
                // }
                this.saveFiles()
                this.formShow = false
                // 传值给父组件刷新列表
                this.$emit('reloadList')
              })
            } else {
              this.isLoading = false
            }
          });
          break
        // 删除
        case 'delete':
          this.$prompt('删除理由', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
          }).then(({ value }) => {
            if (value === null || value === '') {
              this.$messageError('请填写删除理由后重试')
              return
            }
            this.sealDealHttp(res.url, ``, {
              id: this.detailId,
              description: value,
            }, () => {
              this.$messageSuccess('删除成功!')
              this.formShow = false
              // 传值给父组件刷新列表
              this.$emit('reloadList')
            })
          }).catch(() => {
            console.log('请求出现错误');
          });
          break
      }
    },
    saveFiles() {
      for (let k in this.fileSystem) {
        let fileProp = this.fileSystem[k]
        this.$refs[fileProp.compoName].saveAll(this.detailId)
      }
    },
    exportExcel() {
      this.$httpGet(`/buss/assessment/exportExcel?id=${this.detailId}`, null, { responseType: 'blob' }).then(res => {
        // this.$publicUpload.checkFile(res.fileId, "考核评分表.doc")
        var blob = new Blob([res], { type: 'application/vnd.ms-excel;charset=UTF-8' }) //application/vnd.openxmlformats-officedocument.wordprocessingml.document这里表示doc类型
        var downloadElement = document.createElement('a')
        var href = window.URL.createObjectURL(blob) //创建下载的链接
        downloadElement.style.display = 'none'
        downloadElement.href = href
        downloadElement.download = decodeURI('考核评分表.doc') //下载后文件名
        document.body.appendChild(downloadElement)
        downloadElement.click() //点击下载
        document.body.removeChild(downloadElement) //下载完成移除元素
        window.URL.revokeObjectURL(href) //释放掉blob对象
        // var href = window.URL.createObjectURL(blob); //创建下载的链接
        // window.location.href = href;
        // window.URL.revokeObjectURL(href); //释放掉blob对象

      }).catch(res => {
        console.log('请求出现错误', res)
        this.$messageError(this.$route.name + '请求失败')
      })

    },
    // 上传文件前
    beforeUpload(file) {
      if (file.size > 2000 * 1024 * 1024) {
        this.$messageError('上传文件大小不能超过500M')
        return
      }
      let fd = new FormData()
      fd.append('file', file)
      this.$httpPost(`${this.$store.state.httpHost.file}/japi/filesystem/upload?maxFileSize=${file.size}&viewByAnon=true&longLife=false`,
        fd, {
        headers: {
          'Content-Type': 'multipart/form-data; boundary=----WebKitFormBoundaryIOi8qEBAFV1KN25n',
        }
      }).then(res => {
        if (res.data.status === 1) {
          this.fileList.push({
            name: file.name,
            size: file.size,
            url: res.data.link,
            id: res.data.id,
          })
          // 非新建时绑定文件
          if (this.detailType !== 'build') {
            this.bingFileForm([res.data.id], this.fileSystem.part[0])
          }
        } else {
          this.$messageError(res.data.message)
        }
      }).catch(res => {
        console.log('请求出现错误', res);
        this.$messageError(this.$route.name + '上传文件前-请求失败')
      })
    },
    // 删除文件时解绑文件
    removeFile(file, fileList) {
      console.log(file, fileList)
      this.unBingFile(file.id)
      this.selectList.file = fileList
    },
    //  导出excel
    downfile() {
      this.$httpPost(this.$store.state.httpHost.buss + `/buss/assessment/downfile?id=` + this.detailId,
        this.search,
        { responseType: 'blob' }).then(res => {
          var blob = new Blob([res.data], { type: 'application/vnd.ms-excel;charset=UTF-8' }); //application/vnd.openxmlformats-officedocument.wordprocessingml.document这里表示doc类型
          var downloadElement = document.createElement('a');
          var href = window.URL.createObjectURL(blob); //创建下载的链接
          downloadElement.style.display = 'none';
          downloadElement.href = href;
          downloadElement.download = decodeURI("考核评分表.docx"); //下载后文件名
          document.body.appendChild(downloadElement);
          downloadElement.click(); //点击下载
          document.body.removeChild(downloadElement); //下载完成移除元素
          window.URL.revokeObjectURL(href); //释放掉blob对象
        }).catch(e => {
          console.log(e);
          this.$messageError("请求excel模板失败")
        })
    },
    // 查看文件
    checkFile(file) {
      console.log('ssssssss' + file.name)
      this.$httpPost(
        this.$store.state.httpHost.file + `/japi/filesystem/getFilePreview?id=${file.id}&browserType=1`,

      ).then(res => {
        if (res.data.status === 1) {
          window.open(res.data.url.replace("/file", this.$store.state.httpHost.file))
        } else if (res.data.status === 0) {
          this.$messageError(res.data.message)
        } else {
          this.$messageError('在线预览失败 ')

        }                    // window.location.href = res.data.url
      }).catch(res => {
        console.log('请求出现错误', res);
        this.$toast('请求失败!')
      })

    },
    getConstructionTeam() {
      crudDict.getByCode('constructionTeam').then(res => {
        if (res.code == 200) {
          this.constructionTeamList = res.data
        }
      })
    },
    // 绑定文件到表单
    bingFileForm(fileIdsArray, part, callback) {
      if (fileIdsArray.length === 0) return
      this.$httpPost(
        this.$store.state.httpHost.file + '/japi/filesystem/attachment/bindBigBatch',
        [{
          fileid: fileIdsArray, // 文件列表
          form: this.detailId, // 表单
          sys: this.fileSystem.sys,
          module: this.fileSystem.module,
          part: part,
        }]
      ).then(res => {
        if (res.data.status === 1) {
          if (callback) callback()
        } else {
          this.$messageError(res.data.message)
        }
      }).catch(res => {
        console.log('请求出现错误', res);
        this.$toast('请求失败!')
      })
    },
    // 获取绑定的附件
    getFiles() {
      this.fileList = []
      this.$httpGet(
        `${this.$store.state.httpHost.file}/japi/filesystem/attachment/getFilesByAttach?sys=${this.fileSystem.sys}&module=${this.fileSystem.module}&form=${this.detailId}`,
      ).then(res => {
        if (res.data.status === 1) {
          this.fileSystem.attachId = res.data.attachid
          let files = []
          let imgs = []
          if (res.data.attachinfos[0] && res.data.attachinfos[0].part === 'one') {
            files = res.data.attachinfos[0].fileInfo
          } else if (res.data.attachinfos[0] && res.data.attachinfos[0].part === 'two') {
            imgs = res.data.attachinfos[0].fileInfo
          }
          if (res.data.attachinfos[1] && res.data.attachinfos[1].part === 'one') {
            files = res.data.attachinfos[1].fileInfo
          } else if (res.data.attachinfos[1] && res.data.attachinfos[1].part === 'two') {
            imgs = res.data.attachinfos[1].fileInfo
          }
          files.forEach(item => {
            this.fileList.push({
              name: item.name,
              size: item.size,
              link: item.link,
              id: item.id,
              url: this.$store.state.httpHost.file + item.link,
            })
          })
          imgs.forEach(item => {
            this.fileList.push({
              name: item.name,
              size: item.size,
              link: item.link,
              id: item.id,
              url: this.$store.state.httpHost.file + item.link,
            })
          })
        } else {
          this.$messageError(res.data.message)
        }
      }).catch(res => {
        console.log('请求出现错误', res);
        this.$messageError('请求失败!')
      })
    },
    // 解绑已绑定的文件
    unBingFile(fileId, callback) {
      this.$httpPost(
        `${this.$store.state.httpHost.file}/japi/filesystem/attachment/removeBindBatch?attachment=${this.fileSystem.attachId}&fileInfo=${fileId}`
      ).then(res => {
        if (callback) callback()
      }).catch(res => {
        console.log('请求出现错误', res);
        this.$messageError('请求失败!')
      })
    },
    //下载文件
    dlFile(e) {
      var popup = window.open(",");
      popup.location.href = this.$store.state.httpHost.file + e;
      setTimeout(function () {
        popup.close();
      }, 1000);
      // window.open(window.open(this.$store.state.httpHost.file+e))
    },
    changeProject() {
      if (this.formBaseData.sectionId) { this.formBaseData.sectionId = '' }
      this.sectionTree = []
      for (let i = 0; i < this.projectTree.length; i++) {
        if (this.projectTree[i].id == this.formBaseData.projectId) {
          this.sectionTree = this.projectTree[i].children
          if (this.sectionTree.length == 1) {
            this.formBaseData.sectionId = this.sectionTree[0].id
          }
          break;
        }
      }
    },
  }
}
</script>

<style scoped lang="scss">
.el-select.half {
  width: 250px;
}

.el-select.fill {
  width: 800px;
}

.contract_input {
  width: 250px;
}

.contract_input2 {
  width: 240px;
}

.el-input .el-select {
  width: 130px;
}

.fee_add {
  color: #008fe0;
  border-color: #008fe0;
  float: right;
  margin-bottom: 10px;
}

.assessment-score-table {
  td {
    padding: 10px;
    text-align: center;
    .el-form-item {
      margin: 20px 0;
    }
  }
}
</style>
